From 3e083cb724bec0ee2c88ed6c83fc4fcbe571f4ec Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Mon, 10 Mar 2014 16:30:20 -0700 Subject: [PATCH] Share manifest structs --- Makefile | 13 ++++++--- commands/cargo-read-manifest/main.rs | 42 +++++++++++----------------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index b1639adb0..eb6444264 100644 --- a/Makefile +++ b/Makefile @@ -3,23 +3,24 @@ RUSTC_FLAGS ?= --out-dir $(RUSTC_TARGET) -L $(RUSTC_TARGET)/libs TOML_LIB := $(shell rustc --crate-file-name libs/rust-toml/src/toml/lib.rs) HAMMER_LIB := $(shell rustc --crate-file-name libs/hammer.rs/src/lib.rs) +LIBCARGO_LIB := $(shell rustc --crate-file-name libcargo/cargo.rs) default: dependencies commands -dependencies: target/libs/$(TOML_LIB) target/libs/$(HAMMER_LIB) +dependencies: target/libs/$(TOML_LIB) target/libs/$(HAMMER_LIB) target/libs/$(LIBCARGO_LIB) commands: target/cargo-rustc target/cargo-verify-project target/cargo-read-manifest clean: rm -rf target -target/cargo-rustc: target target/libs/$(TOML_LIB) commands/cargo-rustc/main.rs +target/cargo-rustc: target dependencies target/libs/$(TOML_LIB) commands/cargo-rustc/main.rs rustc commands/cargo-rustc/main.rs $(RUSTC_FLAGS) -target/cargo-verify-project: target target/libs/$(TOML_LIB) commands/cargo-verify-project/main.rs +target/cargo-verify-project: target dependencies target/libs/$(TOML_LIB) commands/cargo-verify-project/main.rs rustc commands/cargo-verify-project/main.rs $(RUSTC_FLAGS) -target/cargo-read-manifest: target target/libs/$(TOML_LIB) target/libs/$(HAMMER_LIB) commands/cargo-read-manifest/main.rs +target/cargo-read-manifest: target dependencies target/libs/$(TOML_LIB) target/libs/$(HAMMER_LIB) commands/cargo-read-manifest/main.rs rustc commands/cargo-read-manifest/main.rs $(RUSTC_FLAGS) target/libs/$(TOML_LIB): target libs/rust-toml/src/toml/lib.rs @@ -30,6 +31,10 @@ target/libs/$(HAMMER_LIB): target libs/hammer.rs/src/lib.rs cd libs/hammer.rs && make cp libs/hammer.rs/target/*.rlib target/libs +target/libs/$(LIBCARGO_LIB): target libcargo/cargo.rs + cd libcargo && make + cp libcargo/target/*.rlib target/libs/ + target: mkdir -p $(RUSTC_TARGET)/libs diff --git a/commands/cargo-read-manifest/main.rs b/commands/cargo-read-manifest/main.rs index 498a5c76f..806d76020 100644 --- a/commands/cargo-read-manifest/main.rs +++ b/commands/cargo-read-manifest/main.rs @@ -1,5 +1,6 @@ #[crate_id="cargo-read-manifest"]; +extern crate cargo; extern crate hammer; extern crate serialize; extern crate toml; @@ -10,6 +11,7 @@ use serialize::{Decoder,Decodable}; use serialize::json::Encoder; use toml::from_toml; use semver::Version; +use cargo::{Manifest,LibTarget,ExecTarget,Project}; #[deriving(Decodable,Encodable,Eq,Clone,Ord)] struct SerializedManifest { @@ -18,28 +20,6 @@ struct SerializedManifest { bin: Option<~[ExecTarget]> } -#[deriving(Encodable,Eq,Clone,Ord)] -struct Manifest { - project: ~Project, - lib: ~[LibTarget], - bin: ~[ExecTarget] -} - -#[deriving(Decodable,Encodable,Eq,Clone,Ord)] -struct Target { - name: ~str, - path: Option<~str> -} - -type LibTarget = Target; -type ExecTarget = Target; - -#[deriving(Decodable,Encodable,Eq,Clone,Ord)] -struct Project { - name: ~str, - version: ~str, - authors: ~[~str] -} #[deriving(Decodable,Eq,Clone,Ord)] struct ReadManifestFlags { @@ -79,18 +59,30 @@ fn main() { fn normalize(lib: &Option<~[LibTarget]>, bin: &Option<~[ExecTarget]>) -> (~[LibTarget], ~[ExecTarget]) { if lib.is_some() && bin.is_some() { - (~[], ~[]) + let mut l = lib.clone().unwrap()[0]; // crashes if lib = [] is provided in the Toml file + if l.path.is_none() { + l.path = Some(format!("src/{}.rs", l.name)); + } + + let b = bin.get_ref().map(|b_ref| { + let mut b = b_ref.clone(); + if b.path.is_none() { + b.path = Some(format!("src/bin/{}.rs", b.name)); + } + b + }); + (~[l.clone()], b) } else if lib.is_some() { let mut l = lib.clone().unwrap()[0]; // crashes if lib = [] is provided in the Toml file if l.path.is_none() { - l.path = Some(format!("{}.rs", l.name)); + l.path = Some(format!("src/{}.rs", l.name)); } (~[l.clone()], ~[]) } else if bin.is_some() { let b = bin.get_ref().map(|b_ref| { let mut b = b_ref.clone(); if b.path.is_none() { - b.path = Some(format!("{}.rs", b.name)); + b.path = Some(format!("src/{}.rs", b.name)); } b }); -- 2.30.2